<!--
 * @Author: your name
 * @Date: 2020-07-28 11:52:33
 * @LastEditTime: 2020-08-11 11:35:06
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /website/src/pages/productList.vue
--> 
<template>
  <div>
    <div class="container">
      <div class="product-content">
        <left-side-bar :title="title" :contact="contact">
          <!-- <slot name="currentTitle"></slot> -->
          <template v-slot:currentTitle>
            <p>企业新闻</p>
            <p>公司新闻</p>
            <p>行业新闻</p>
          </template>
        </left-side-bar>
        <div class="product-content_right">
          <p class="current-position">
            <span>当前所在位置:</span>
            <span>
              首页
              <i class="icon-arrow">>>></i>
            </span>
            <span>{{title}}</span>
          </p>
          <div class="product-item">
            <div class="news-title">
              <h2>{{detail.noticetitle}}</h2>
              <p>
                <span class="time">发布时间: {{getLocalTime(detail.createtime) || '时间未知'}}</span>
                <span>阅读次数: {{detail.read || 0}}</span>
              </p>
            </div>
            <div class="news-content">
              {{detail.noticecontent}}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
import Qs from 'qs'
import LeftSideBar from '../components/LeftSideBar'

export default {
  name: 'detail',
  components: {
    LeftSideBar
  },
  data () {
    return {
      title: '',
      id: '',
      detail: {},
      contact: {}
    }
  },
  mounted() {
    /* eslint-disable */
    this.title = this.$route.params.title || '新闻详情'
    this.id = this.$route.params.id
    this.contact = JSON.parse(window.localStorage.getItem('homeData')).sysContact || {}
    this.getNewsDetail()
  },
  methods: {
    getLocalTime (nS) {     
      return new Date(parseInt(nS)).toLocaleString().replace(/:\d{1,2}$/,' ');     
    },
    getNewsDetail() {
      axios.post('/newsInfo', Qs.stringify({
        id: this.id
      })).then(res => {
        if (res.data.msg.code === '0')  {
          this.detail = res.data.data
        } else {
          this.detail = {}
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .product-content{
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    margin: 15px 0;
    .product-content_right{
      flex-grow: 1;
      margin-left: 35px;
      align-items: center;
      .current-position{
        padding: 5px 0;
        font-size: 14px;
        border-bottom: 1px solid #888;
        span{
          .icon-arrow{
            margin: 0 10px;
          }
        }
      }
      .product-item{
        width: 100%;
        .news-title{
          padding: 30px 0;
          text-align: center;
          h2{
            font-weight: normal;
            color: #888;
            font-size: 28px;
          }
          p{
            width: 400px;
            margin: 10px auto;
            padding: 5px 0;
            color: #666;
            font-size: 14px;
            border-top: 1px dotted #ccc;
            border-bottom: 1px dotted #ccc;
            .time{
              margin-right: 10px;
            }
          }
        }
        .news-title{
          font-size: 14px;
          color: #666;
        }
      }
    }
  }
</style>
